<?php 
define('PAGE_NEED_PRI','PRI_EDIT');
session_start();
include_once "main.php";

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title> Bios 管理中心 </title>
<link href="../css/control.css" rel="stylesheet" type="text/css" />
<script src="../js/jquery-1.5.2.min.js"  language="javascript" ></script>

<link href="../css/crop/jquery.Jcrop.css" rel="stylesheet" type="text/css" />
<script src="../js/jquery.Jcrop.min.js"  language="javascript" ></script>

<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
 <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>

<script src="uploadify/swfobject.js"  language="javascript" ></script>
<script src="uploadify/jquery.uploadify.v2.1.4.min.js"  language="javascript" ></script>
<link href="uploadify/uploadify.css" rel="stylesheet" type="text/css" />
<style>
.ui-dialog .ui-dialog-titlebar-close 
{
	text-align:left;
}
</style>


</head>

<body>
<div id="cropdialog" title="Crop image"></div>
<script language="javascript">
$(function(){
				//init file upload
				$(".uploadifyupload").each(function(){
					var current_id = $(".uploadifyupload").attr('id');
					var previous_img_id = current_id + '_img';
					$(".uploadifyupload").uploadify({
						'uploader': 'uploadify/uploadify.swf',
						'cancelImg': 'uploadify/cancel.png',
						'script': 'upload.php',
						'folder': 'files',
						'buttonText':'Choose',
						'multi': false,
						'fileExt':'*.jpg;*.jpeg;*.gif;*.png',
  						'fileDesc':'Image Files',
						'auto': true,
						'queueSizeLimit':1,
						'scriptData':{'<?php echo session_name();?>':'<?php echo session_id();?>','responsetype':'sizeinfo'},
						'displayData': 'speed',
						'onComplete':function(event,queueID,fileObj,response,data){
							var responseObj = eval("("+response+")");
							var fileName = responseObj.name;
							var i_width = responseObj.w;
							var i_height = responseObj.h;
							var i_show_height = 300;
							var i_scale = i_show_height/i_height;
							var i_show_width = i_width*i_scale;
							
							var crop_width = 142;
							var crop_height = 110;
							var crop_show_width = crop_width*i_scale;
							var crop_show_height = crop_height*i_scale;
							
							
							var crop_box_x = (i_show_width - crop_show_width)/2;
							var crop_box_y = (i_show_height - crop_show_height)/2;
							
						
							var select_x;
							var select_y;
							var select_w;
							var select_h;
							
						  $('#'+previous_img_id).attr('src','../upfiles/tmp/' + fileName);
						  $('input[name=ajaxf_'+current_id+']').val(fileName);
											
							$( "#cropdialog").dialog({
							 	'width':i_show_width + 50,
							 	'height':i_show_height + 128,
								buttons:[{'text':'OK','click':function(){
									p_src = "tmp/" + fileName;
									var crop_file_name = fileName + "."+crop_width+"x"+crop_height+".jpg";
									p_des = "tmp/" + crop_file_name;
									
									p_width = crop_width;
									p_height = crop_height;
									p_c_x = select_x/i_scale;
									p_c_y = select_y/i_scale;
									p_c_width = select_w/i_scale;
									p_c_height = select_h/i_scale;
			
									$.post("crop.php", {'src': p_src,'des':p_des,'width':p_width,'height':p_height,'c_x':p_c_x,'c_y':p_c_y,'c_width':p_c_width,'c_height':p_c_height},function(date){							
										$( "#cropdialog").html('');
										$( "#cropdialog").dialog("destroy");
									});

								}}]
							});
							$( "#cropdialog").html("<img src='../upfiles/tmp/"+fileName+"' id='cropbox' width='"+i_show_width+"' height='"+i_show_height+"'/> ");
							$('#cropbox').Jcrop({ 
							onSelect:function(c){
								select_x = c.x;
								select_y = c.y;
								select_w = c.w;
								select_h = c.h;							
								
							},
							/*setSelect:[crop_box_x, crop_box_y,crop_box_x + crop_show_width, crop_box_y + crop_show_height],*/
							aspectRatio:crop_width/crop_height});
						},
						'onError':function(event,queueId,fileObj,errorObj){
							alert(errorObj);
						}
					});
				});
				
				
				

});
</script>


<script type="text/javascript">
var xmlobj;                                     //定义XMLHttpRequest对象
function CreateXMLHttpRequest()
{
    if(window.XMLHttpRequest)
{//Mozilla浏览器
    xmlobj=new XMLHttpRequest();
    if(xmlobj.overrideMimeType)
    {//设置MIME类别
       xmlobj.overrideMimeType("text/xml");
    }
}
else if(window.ActiveXObject)
{//IE浏览器
   try
   {
    xmlobj=new ActiveXObject("Msxml2.XMLHttp");
   }
   catch(e)
   {
    try
    {
     xmlobj=new ActiveXobject("Microsoft.XMLHttp");
    }
    catch(e)
    {
    }
   }
}
}
function Validate()                             //主程序函数
{


if(document.form1.username.value!=""){


    CreateXMLHttpRequest();                     //创建对象
    var showurl = "request.php?username=" + document.getElementById ("username").value;                                    //构造URL
    xmlobj.open("GET", showurl, true);          //调用request.php
    xmlobj.onreadystatechange = StatHandler;    //判断URL调用的状态值并处理
    xmlobj.send(null);                          //设置为不发送给服务器任何数据
}
function StatHandler()                          //用于处理状态的函数
{
    if(xmlobj.readyState == 4 && xmlobj.status == 200)                                                                      //如果URL成功访问，则输出网页
    {
document.getElementById("msg").innerHTML=xmlobj.responseText ;
    }
	
	
	}
}
</script>











<a name="top" id="top"></a>
<div id="all"><!--Wrap start //-->
<div id="main" class="clearfix"><!--main start //-->
<div id="top-1"><?php include_once('blog_top_btn.php');?>
</div>
<!--Content for  id "submenu" Goes Here //-->
<div id="submenu">
<?php include_once('admin_main_btn.php');?>
  </div>
 <!--Content for  id "contact" Goes Here //-->
 <div id="contact-admin">
 
   
   
<?php 
//修改数据
$action=make_safe($_REQUEST["action"]);
$username=make_safe($_REQUEST["usernamepage"]);
$name=make_safe($_REQUEST["name"]);
$tel=make_safe($_REQUEST["tel"]);
$email=make_safe($_REQUEST["email"]);
$msn=make_safe($_REQUEST["msn"]);
$address=make_safe($_REQUEST["address"]);
$oldimages=make_safe($_REQUEST["oldimages"]);
$content=$_REQUEST["content"];
if($_SESSION['PRI_ADMIN'] == "1")
	$mastereditname = $_REQUEST["mastereditname"];
else
	$mastereditname = $_REQUEST["username2"];

if($action=="add"){
$sql = "select count(*) AS `co` from guanli where username = '$username'";
$result=mysql_query($sql);
if($result === false)
{
	echo mysql_error();
	echo $sql;
	exit();
}

$row = mysql_fetch_assoc($result);
if ($row['co'] > 0){
	echo "<script> alert('[".$username."] 已有的[管理員帳號]！');history.back();</script>";
	exit();
}
$images = $_REQUEST['ajaxf_images'];

$update_column_sql = "password='$password',username='$username',mastereditname='$mastereditname',box4='1',name='$name',tel='$tel',email='$email',msn='$msn',address='$address',content='$content',";

if(strlen($images) > 0)
{
	//Move horizen image
	$srcPath = dirname(dirname(__FILE__)).'/upfiles/tmp/'.$images.'.142x110.jpg';
	$tarPath = dirname(dirname(__FILE__)).'/upfiles/'.$images.'.142x110.jpg';
	copy($srcPath,$tarPath);
	unlink($srcPath);
	//move vetical image
	$srcPath = dirname(dirname(__FILE__)).'/upfiles/tmp/'.$images;
	$tarPath = dirname(dirname(__FILE__)).'/upfiles/'.$images;
	copy($srcPath,$tarPath);
	unlink($srcPath);
	
	$tarPath = $_REQUEST['ajaxf_images'];
	$update_column_sql  .= "images='$tarPath',";
}
if(isset($_REQUEST['lock']))
	{
		//check lacok max number
		$check_sql = sprintf("SELECT count(1) AS `co` FROM `guanli` WHERE   `lock`='Y' AND `id` != %d",$id);
		$check_result=mysql_query($check_sql);
			if($check_result == false)
			{
				$error = sprintf("%s%s%s",mysql_error(),__FILE__,__LINE__);
				echo $error;
				exit();
			}
			$check_info =mysql_fetch_assoc($check_result);
			if($check_info['co'] > 4)
			{
				echo "<script>alert('鎖定失敗,最多鎖定五個作者');window.location.href='admin-acc-e-main.php';</script>";
				exit();
			}
			
		$lock = 'Y';
		$update_column_sql .= sprintf("`lock_start`='%s',",mysql_real_escape_string($_REQUEST['lock_start']));
		$update_column_sql .= sprintf("`lock_end`='%s',",mysql_real_escape_string($_REQUEST['lock_end']));
	}else{
		$lock = '';
	}
$update_column_sql .= "`lock`='$lock',";

$update_column_sql = substr($update_column_sql,0,-1);
$sql = sprintf("INSERT `guanli` SET %s",$update_column_sql);
if($query=mysql_query($sql))

{
if($_SESSION["PRI_ADMIN"]==1 ){
   echo "<script>alert('資料增加成功！');window.location.href='admin-acc-e-main.php';</script>";
   }else{
    echo "<script>alert('資料增加成功！');window.location.href='admin-acc-e-main.php?id=".$id."';</script>";
	}
 }
 
 else
  {
  
  echo mysql_error();
  exit();
  if($_SESSION["PRI_ADMIN"]==1){
   echo "<script>alert('資料增加失敗！');window.location.href='admin-acc-e-main.php';</script>";
      }else{
   echo "<script>alert('資料增加失敗！');window.location.href='admin-acc-e-main.php?id=".$id."';</script>";
   }
   
  }
  }



?>


   <form   action="?action=add" method="post" name="form1"     enctype="multipart/form-data"    target="_self"    >
   <?php if($_SESSION['PRI_ADMIN'] == '1'):?>
   <table border="0" cellspacing="0" cellpadding="0">
     <tr>
       <td>帳號權限設定：</td>
     </tr>
     <tr>
       <td><ul>
         <li>編輯部選這邊：</li>
		 <li>master name 
<select name="mastereditname"  id="office1"  onchange="ChangeSelect(this.value,'office2','',Office)" >
 <?php 
 $query=mysql_query("select id,username,name from guanli where box2='1' order by id");
 
 
	       if($query==true){
		   while($myrow=mysql_fetch_array($query)){
		  ?>
		<option value="<?php echo $myrow['username'];?>"><?php echo $myrow['name'];?></option>
 <?php }}?>
 
 
</select>
          </li>
		  

			  
          
         
       </ul></td>
     </tr>
	 
	 
	 

	 
	 
	 
	 
     
   </table>
   
   <?php endif;?>
   
   
   
   <table border="0" cellspacing="0" cellpadding="0">
     <tr>
       <td colspan="2">帳號相關資訊：</td>
     </tr>
     
     
	 <tr>
       <td class="contact-admin-l">登入帳號：</td>
       <td class="contact-admin-r"><input name="usernamepage" id="username" type="text" class="contact-admin-keyin" onClick="Validate();"  onBlur="Validate();"  /> <input type="button" value="驗證帳號" onClick="Validate();"><span class="redText">*</span><div  id="msg"></div>
     </tr>
 
	 
	 <tr>
       <td class="contact-admin-l">姓名：</td>
       <td class="contact-admin-r"><label for="textfield2"></label>
         <input name="name" type="text" class="contact-admin-keyin" id="textfield2" /></td>
     </tr>
	 
     <tr>
       <td class="contact-admin-l">電子郵件：</td>
       <td class="contact-admin-r"><input name="email" type="text" class="contact-admin-keyin"  /></td>
     </tr>
	 <tr>
       <td class="contact-admin-l">MSN：</td>
       <td class="contact-admin-r"><input name="msn" type="text" class="contact-admin-keyin"  /></td>
     </tr>
     <tr>
       <td class="contact-admin-l">連絡電話：</td>
       <td class="contact-admin-r"><input name="tel" type="text" class="contact-admin-keyin"  /></td>
     </tr>
     <tr>
       <td class="contact-admin-l">個人網址：</td>
       <td class="contact-admin-r"><input name="address" type="text" class="contact-admin-keyin"  /></td>
     </tr>
	 <tr>
       <td class="contact-admin-l">個人圖像：</td>
       <td class="contact-admin-r" nowrap>
      <img id="images_img" id="images" src="../upfiles/upfiles/default.png" width="35" height="35" />
       <input type="hidden" name="ajaxf_images" value=""/>
       <input name="images" id="images" class="uploadifyupload" type="file" size="50"  />
       </td>
	 </tr>
	 <tr>
       <td class="contact-admin-l">個人簡介：</td>
       <td class="contact-admin-r"><?php 
include('../fckeditor/fckeditor.php');
	$oFCKeditor = new FCKeditor('FCKeditor1')  ; 
	$oFCKeditor->BasePath = '../fckeditor/' ;    
	$oFCKeditor->ToolbarSet = 'Default' ; 
	$oFCKeditor->InstanceName = 'content' ; 
	$oFCKeditor->Width = '100%' ; 
	$oFCKeditor->Height = '400' ; 
	//$oFCKeditor->Value  = $row['content']; 
	//$oFCKeditor->Value  = $row->content; 
$oFCKeditor->Create();?></td>
	 </tr>
     <tr>
       <td class="contact-admin-l">&nbsp;</td>
       <td class="contact-admin-r">
         <input type="submit" name="imageField" src="images/btn-add.gif"    />
      </td>
     </tr>
     <tr>
       <td class="contact-admin-l">&nbsp;</td>
       <td class="contact-admin-r">&nbsp;</td>
     </tr>
   </table>
   </form>
   
   
   
   
   
   
   
   
   
   
   
   
   
   
 </div>
</div><!-- main end //-->
</div><!--Wrap end //-->
<div id="botton">
 <?php include_once('blog_botton_btn.php');?>
</div>




   <script language="javascript">
	function check(form1){
	
	
if(document.form1.mastereditname.value==""){
			alert("请選擇  mastereditname!");document.form1.mastereditname.focus();return false;		
		}
		
		
		if(document.form1.editname.value==""){
			alert("请選擇 editname!");document.form1.editname.focus();return false;		
		}
	
	
	
	
		if(document.form1.username.value==""){
			alert("请输入管理員帳號!");document.form1.username.focus();return false;		
		}
		if(form1.password.value==""){
			alert("请输入管理員 密碼!");document.form1.password.focus();return false;
		}
		
		if(document.form1.password.value!=document.form1.conpassword.value){
			alert("對不起，您輸入的確認密碼不正確!");document.form1.conpassword.focus();return false;
		}
		
		
		if(document.form1.name.value==""){
			alert("请输入管理員 姓名!");document.form1.name.focus();return false;		
		}
		
		if(document.form1.email.value==""){
			alert("请输入管理員 電子郵件!");document.form1.email.focus();return false;		
		}
		
		
		if(document.form1.msn.value==""){
			alert("请输入管理員 MSN!");document.form1.msn.focus();return false;		
		}
		
		if(document.form1.tel.value==""){
			alert("请输入管理員 聯絡電話!");document.form1.tel.focus();return false;		
		}
		
		
		if(document.form1.address.value==""){
			alert("请输入管理員 個人網址!");document.form1.address.focus();return false;		
		}
		
	}
</script>
   







</body>
</html>